import {
  getLoginCode,
  codeToToken,
  getUserInfo
} from './service/login-api';
export const TOKEN_KEY = 'token_key';
App({
  onLaunch: function () {
    // 获取系统信息
    const info = wx.getSystemInfoSync()

    // 获取屏幕宽度
    this.globalData.screenWidth = info.screenWidth

    // 获取屏幕高度
    this.globalData.screenHeight = info.screenHeight

    // 获取头部状态栏高度（时间、电量）
    this.globalData.statusBarHeight = info.statusBarHeight;

    this.loginHandle();
  },
  async loginHandle() {
    // 获取登录code
    const code = await getLoginCode();

    // 根据code从服务器获取token
    const {token} = await codeToToken(code)

    // 保存到本地
    wx.setStorageSync(TOKEN_KEY, token);
  },
  globalData: {
    screenWidth: 0,
    screenHeight: 0,
    statusBarHeight: 0,
    navBarHeight: 44
  }
})